package com.servlet.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Title: HelloServlet
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2023/12/21 11:16
 */
public class HelloServlet extends HttpServlet {

    public  HelloServlet() {
        System.out.println("HelloServlet.............");
    }

    /**
     * 接收get请求
     * @param req  接收参数
     * @param resp 响应内容
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         // 响应数据
        resp.getWriter().write("hello servlet get!");
    }

    /**
     * 接收post请求
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 响应数据
        resp.getWriter().write("hello servlet post!");
    }
}
